<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>优惠券领取</title>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
    <script src="/js/jquery-3.3.1.min.js"></script>
</head>
<body style="height: 100%">
<form>
    <input type="hidden" th:value="${isSuccess}"/>
    <input type="hidden" id="extJson" th:value="${extJson}">
    <input type="hidden" id="card_id"  th:value="${cpnCodeInfo.wxCardId}">
</form>

<div id="cardTitleView" style="width: 80%;padding: 50px 0;position:fixed;left: 0;
top: 50%;margin-left: 10%;margin-top: -175px;text-align: center;
background: #fff;border-radius: 10px;box-shadow: 15px 15px 15px #dddddd;
">
    <div style="font-size: 50px">正在出券请稍后...</div>
    <img src="/image/cardOut.gif" style="width: 150px">
</div>

<script type="text/javascript">
    function jssdk() {
        $.ajax({
                     url : "/wx_jsSdk/config",
                     type : 'post',
                     dataType: 'json',
                     contentType: "application/x-www-form-urlencoded; charset=utf-8",
                     data : {
                         'url' : encodeURI(location.href.split('#')[0])
                     },
                   success : function(result) {
                         if(result.code==1){
                             var data = result.data;
                             wx.config({
                                 debug : false,
                                 appId : data.appId,
                                 timestamp : data.timestamp,
                                 nonceStr : data.nonceStr,
                                 signature : data.signature,
                                 jsApiList : ['addCard',"getLocation","closeWindow" ]
                             });
                         }else {
                            alert(result.message);
                         }

                     }
             });
             }
         function isWeiXin5() {
                 var ua = window.navigator.userAgent.toLowerCase();
                 var reg = /MicroMessenger\/[5-9]/i;
                 return reg.test(ua);
             }
          window.onload = function() {
                 jssdk();
         };

        wx.ready(function(){

            $("#cardTitleView").css("display","none");
            wx.addCard({
                cardList: [{
                    cardId:  $("#card_id").val(),
                    cardExt: $("#extJson").val()
                }],
                success: function (res) {
                    var cardList = res.cardList; // 添加的卡券列表信息
                }
            });
            wx.closeWindow();
            });
            wx.error(function(res){
                alert(res);
            });
            

</script>

</body>
</html>